package com.lottery;

import java.security.SecureRandom;
import java.util.List;
import java.util.Random;

/**
 * 抽奖程序入口
 */
public class LotteryMain {

    public static void main(String[] args) {
        // 获取参数抽奖的人
        List<String> list = GeneratorData.generatorData();
        // 开始抽奖
        String prizePerson = doLottery(list, LotteryConfig.firstPrize, LotteryConfig.secondPrize, LotteryConfig.thirdPrize);
        // 输出抽奖结果
        System.out.println(prizePerson);
    }

    /**
     * 抽奖算法
     * @param list
     * @param prizePool
     * @return String
     */
    public static String doLottery(List<String> list,int... prizePool) {
        Random random = new SecureRandom();
        StringBuilder sb = new StringBuilder();
        String lineSeparator = System.getProperty("line.separator", "\r\n");

        for (int i = 0; i < prizePool.length; i++) {
            sb.append(i + 1).append("等奖:");
            for (int j = 0; j < prizePool[i]; j++) {
                int randomInt = random.nextInt(list.size());
                sb.append(list.remove(randomInt)).append(",");
            }
            sb.append(lineSeparator);
        }

        return sb.toString();
    }
}
